<%
layout("layout.html",{title:'待处理列表', first: '充值', second: '待处理列表', menu: '充值'}){
%>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">待处理列表</h3>
            </div>
            <div class="box-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>id</th>
                        <th>金额</th>
                        <th>时间</th>
                        <th>用户</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <% for (recharge in recharges) { %>
                    <tr id="rechage-${recharge.id}">
                        <td>${recharge.id}</td>
                        <td>${recharge.money / 100}</td>
                        <td>${recharge.createTime,dateFormat="yy-MM-dd HH:mm"}</td>
                        <td>${recharge.user.nickname}</td>
                        <td>
                            <a href="javascript:" data-id="${recharge.id}" class="successButton">通过</a>
                            |
                            <a href="javascript:" data-id="${recharge.id}" class="failButton">拒绝</a></td>
                    </tr>
                    <% } %>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script src="${ctxPath}/js/net.js"></script>
<script>
    $(document).ready(function(){
        $('.successButton').click(function () {
            var id = $(this).data('id');
            net()
                .url('${ctxPath}/api/recharges/' + id + '/' + 'Success')
                .success(function(response) {
                    if (response.code == 0) {
                        $.growl.notice({title: '操作成功', message: '通过充值请求成功' });
                        $('#rechage-' + id).remove();
                    } else {
                        $.growl.error({title: '错误', message: response.message });
                    }
                })
                .error(function (err) {
                    $.growl.error({title: '错误', message: '网络错误' });
                })
                .put();
        });
        $('.failButton').click(function () {
            var id = $(this).data('id');
            net()
                .url('${ctxPath}/api/recharges/' + id + '/' + 'Fail')
                .success(function (response) {
                    if (response.code == 0) {
                        $.growl.notice({title: '操作成功', message: '拒绝充值请求成功' });
                        $('#rechage-' + id).remove();
                    } else {
                        $.growl.error({title: '错误', message: response.message });
                    }
                })
                .error(function (err) {
                    $.growl.error({title: '错误', message: '网络错误' });
                })
                .put();
        });
    });
</script>
<% } %>